package no.uib.kwikktaim.gui.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import no.uib.kwikktaim.gui.MainWindow;
import no.uib.kwikktaim.utils.PlayerOptions;

public class PlayPause implements ActionListener {

	private MainWindow mw;
	private boolean pressedPause = false;

	public void setPressedPause(boolean pressedPause) {
		this.pressedPause = pressedPause;
	}

	public PlayPause(MainWindow caller) {
		mw = caller;
	}

	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource().equals(mw.getButtonStop())) {
			mw.stop();
			mw.setPlaypause(PlayerOptions.PAUSE);
		}
		else {
			PlayerOptions po = mw.getPlaypause();
			if (po == PlayerOptions.PAUSE) {
				// Play video stuff here
				mw.setPlaypause(PlayerOptions.PLAY);
				if(pressedPause)
					mw.play();
				else
					mw.loadAndPlay();
			} else {
				// Play video stuff here
				mw.setPlaypause(PlayerOptions.PAUSE);
				pressedPause = true;
			}
		}
	}

}
